import axios from 'axios'
const instance = axios.create({
    //baseURL: 'https://www.fastmock.site/mock/ae8e9031947a302fed5f92425995aa19/jd/',
    baseURL: 'http://localhost:3000',
    timeout: 3000,
    withCredentials: true //允许跨域传递cookie
})
/**
 * post请求
 * @param {*} url 
 * @param {*} data 
 * @returns 
 */
export const post = (url, data = {}) => {
    return new Promise((resolve, reject) => {
        instance.post(url, data, {
            headers: {
                "Content-Type": "application/json"
            }
        }).then((response) => {
            resolve(response)
        }, err => {
            reject(err)
        })
    })
}
/**
 * get请求
 * @param {*} url 
 * @param {*} params 
 * @returns 
 */
export const get = (url, params = {}) => {
    return new Promise((resolve, reject) => {
        instance.get(url, { params }).then((response) => {
            resolve(response)
        }, err => {
            reject(err);
        })
    })
}
/**
 * patch请求
 */
export const patch = (url, data) => {
    return new Promise((resolve, reject) => {
        instance.patch(url, { data }, {
            headers: {
                "Content-Type": "application/json"
            }
        }).then(response => {
            resolve(response)
        }, err => {
            reject(err);
        })
    })
}